export class EventBus {
  constructor() { this.handlers = new Map(); }
  on(type, handler) {
    if (!this.handlers.has(type)) this.handlers.set(type, new Set());
    this.handlers.get(type).add(handler);
  }
  off(type, handler) {
    const set = this.handlers.get(type);
    if (set) set.delete(handler);
  }
  emit(evt) {
    const set = this.handlers.get(evt.type);
    if (set) set.forEach(h => h(evt.data));
  }
}